home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / a_utils / perl / perl5a1.lha / perl5alpha1 / do / accept next >
Encoding:
Text File  |  1992-08-15  |  965 b   |  52 lines

  1. void
  2. do_accept(TARG, nstab, gstab)
  3. STR *TARG;
  4. STAB *nstab;
  5. STAB *gstab;
  6. {
  7.     register STIO *nstio;
  8.     register STIO *gstio;
  9.     int len = sizeof buf;
  10.     int fd;
  11.  
  12.     if (!nstab)
  13.     goto badexit;
  14.     if (!gstab)
  15.     goto nuts;
  16.  
  17.     gstio = stab_io(gstab);
  18.     nstio = stab_io(nstab);
  19.  
  20.     if (!gstio || !gstio->ifp)
  21.     goto nuts;
  22.     if (!nstio)
  23.     nstio = stab_io(nstab) = stio_new();
  24.     else if (nstio->ifp)
  25.     do_close(nstab,FALSE);
  26.  
  27.     fd = accept(fileno(gstio->ifp),(struct sockaddr *)buf,&len);
  28.     if (fd < 0)
  29.     goto badexit;
  30.     nstio->ifp = fdopen(fd, "r");
  31.     nstio->ofp = fdopen(fd, "w");
  32.     nstio->type = 's';
  33.     if (!nstio->ifp || !nstio->ofp) {
  34.     if (nstio->ifp) fclose(nstio->ifp);
  35.     if (nstio->ofp) fclose(nstio->ofp);
  36.     if (!nstio->ifp && !nstio->ofp) close(fd);
  37.     goto badexit;
  38.     }
  39.  
  40.     str_nset(TARG, buf, len);
  41.     return;
  42.  
  43. nuts:
  44.     if (dowarn)
  45.     warn("accept() on closed fd");
  46.     errno = EBADF;
  47. badexit:
  48.     str_sset(TARG,&str_undef);
  49.     return;
  50. }
  51.  
  52.